<%@ page language="java" import="java.util.*" pageEncoding="UTF-8" %>
<%@ include file="/website/common/base.jsp" %>

<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title>${webname }-历史采购</title>
    <%@ include file="/website/common/common.jsp" %>
    <link href="${webctx }/css/manage.css" rel="stylesheet" type="text/css"/>
    <link href="${webctx }/css/payment.css" rel="stylesheet" type="text/css"/>
    <style>
        .cart-bd {
            border: 1px solid #eee;
            margin-top: 20px;
        }

        .row-item {
            height: 148px;
            line-height: 22px;
            color: #666;
            border-bottom: 1px solid #eee;
            clear: both;
            overflow: hidden;
        }

        .row-item:last-child {
            border-bottom: none;
        }

        .row-item:hover {
            background-color: #f8f8f8;
        }

        .row-item .pic, .row-item .text, .row-item .row-btn {
            float: left
        }

        .row-item .pic {
            padding: 14px 14px 14px 24px;
        }

        .row-item .text {
            padding: 40px 0 0 10px;
            font-size: 12px;
        }

        .row-item .text strong {
            color: #fc5759;
            font-size: 16px;
        }

        .row-item .text.cost {
            text-align: center;
        }

        .row-item .text.cost p {
            margin-bottom: 5px;
        }

        .row-item .text.cost span {
            display: inline-block;
            height: 18px;
            background-color: #ff6767;
            padding: 0 3px;
            line-height: 18px;
            color: #fff;
            margin-left: 3px;
        }

        .row-item .title {
            width: 230px;
        }

        .row-item .title a {
            font-size: 14px;
        }

        .row-item .title a:hover {
            color: #ff6767;
        }

        .row-item .title h3 {
            margin-bottom: 5px;
            width: 100%;
            overflow: hidden;
            white-space: nowrap;
            text-overflow: ellipsis;
        }

        .row-item .title p{
            width:225px;
            overflow: hidden;
            white-space: nowrap;
            text-overflow:ellipsis;
        }
        .row-item .details p{
            width:175px;
            overflow: hidden;
            white-space: nowrap;
            text-overflow:ellipsis;
        }

        .row-item .details {
            width: 180px;
        }

        .row-item .details p:first-child {
            margin-bottom: 5px;
        }

        .row-item .cost {
            width: 140px;
        }

        .row-item .row-btn {
            padding-top: 40px;
            padding-left: 30px
        }

        .row-item .buy-Num-bd {
            margin-right: 8px;
        }

        .row-item .buy-btn a {
            width: 74px;
            line-height: 26px;
            height: 26px;
            margin-right: 10px;
        }

        .row-item .rest-btn a {
            line-height: 26px;
            height: 26px
        }

        .row-item .buy-btn i {
            top: 6px;
        }

        .row-item .rest-btn i {
            background: none;
            top: 5px;
        }

        .array-item .title a {
            color: #333;
        }

        .array-item .title a:hover em {
            color: #ff6767;
        }

        .buy-btn2.buy-add-cart a {
            margin-top: 4px;
        }

        .row-item .repertory {
            margin-top: 5px;
            width: 155px;
            font-size: 12px;
            color: #888;
        }

        .right-tit {
            height: 40px;
            line-height: 40px;
            padding-left: 0px;
            font-size: 16px;
            margin-top: 10px;
            position: relative;
            background: #fff;
            color: #0daeff;
        }

        .select select {
            width: 240px;
            height: 30px;
            margin: 10px 0;
        }

        .row-item .list-title {
            width: 80px;
            height: 100%;
            text-align: center;
        }

        .row-item .list-title.odd {
            background-color: #e6e6e6;
        }

        .row-item .list-title.even {
            background-color: #f4f4f4;
        }

        .row-item .list-title h1 {
            color: #0daeff;
            font-size: 30px;
            margin-top: 40px;
        }

        .row-item .list-title p {
            color: #666;
            font-size: 12px;
            margin-top: 28px;
        }

        .rig-nav {
            z-index: 22;
            position: fixed;
            top: 60%;
            right: 0;
        }

        .rig-nav a {
            z-index: 2;
            position: absolute;
            right: 0;
            top: 0;
            width: 40px;
            height: 40px;
            cursor: pointer;
        }

        .rig-nav a:hover > span {
            display: block;
        }

        .rig-nav a span {
            display: none;
            position: absolute;
            top: 4px;
            right: 40px;
            width: 80px;
            height: 32px;
            background-color: #fff;
            font-size: 12px;
            color: #666;
            line-height: 32px;
            text-align: center;
            box-shadow: 0px 0px 8px 0px #999;
        }

        .rig-nav a span i {
            position: absolute;
            top: 6px;
            right: -6px;
            width: 0;
            height: 0;
            border-top: 10px solid transparent;
            border-bottom: 10px solid transparent;
            border-left: 10px solid #fff;
        }

        .rig-nav .service {
            background: url("${webctx}/images/ico-service.png") no-repeat;
        }

        .rig-nav .go-top {
            top: 41px;
            background: url("${webctx}/images/go-top.png") no-repeat;
        }

        .rig-nav span {
            z-index: 1;
            position: absolute;
            top: 35px;
            right: 0;
            height: 10px;
            width: 10px;
            background-color: #666;
        }

        .add-more {
            margin-top: 18px;
            height: 27px;
            background-color: #f4f4f4;
            text-align: center;
            margin-bottom: 30px;
            line-height: 27px;
            color: #666;
            font-size: 12px;
        }

        .add-more a {
            height: 27px;
            line-height: 27px;
            padding-right: 20px;
            background: url("${webctx}/images/ico-arrows-show.png") no-repeat center right;
            font-size: 12px;
            color: #666;
        }

    </style>
</head>
<body>
<%@ include file="/website/common/top.jsp" %>
<%@ include file="/website/common/head.jsp" %>
<%@ include file="/website/common/menu.jsp" %>

<div class="warp-body" style="background-color: #fff;">
    <div style="width: 100%; height: 3px; background-color: #0daeff;"></div>
    <div class="rig-nav">
        <span></span>
        <%--'<a onclick="NTKF.im_openInPageChat(\'kf_9798_1494052158469\')">' +--%>
        <%--'<i class="KFview"></i>' +--%>
        <%--'<span>联系客服</span>' +--%>
        <%--'</a>' +--%>


        <a class="service" onclick="BaiduBusiness();"><span>联系客服 <i></i></span></a>
        <a class="go-top" href="javascript:;"><span>返回顶部 <i></i></span></a>
    </div>
    <div class="inner clearfix">
        <div class="left-main">
            <div class="left-inner">
                <%@ include file="/website/user/left.jsp" %>
            </div>
        </div>
        <div class="right-main">
            <div class="right-inner">
                <div class="right-tit">历史采购</div>

                <div class="select">
                    <select id="selectOp" onchange="hislistnew()">
                        <option name="timetype0" value="1">最近三个月</option>
                        <option name="timetype1" value="2">最近六个月</option>
                        <option name="timetype" value="3">最近一年</option>
                    </select>
                </div>

                <div class="cart-bd" id="hislistnew_id">


                </div>
                <div class="add-more" style="display: none"><a href="javascript:paging(); ">点击加载更多</a></div>
                <!-- end -->
            </div>
        </div>
    </div>
</div>
<div style="width:100%;height: 2px;background-color:#ccc;"></div>
<%@ include file="/website/common/foot-site.jsp" %>
<%@ include file="/website/BaiduBusiness.jsp" %>
</body>
</html>
<script>
    $(function () {
        hislistnew();
    });
    var timef_t = true;
    function selectgr() {
        var timeTypeVal = $("#selectOp").val();
        $("#selectOp").addClass("aaaa");
        return timeTypeVal;
    }

    var pno = 1;
    var pnumber = 1;
    function hislistnew() {
        var timeType = selectgr();
        $w.httpRequest({
            url: ctx + "/order/hislistnew",
            data: {"pno": 1, "timeType": timeType ,"platform" : 1},
            ok: function (ret) {
                pno = 1;
                pnumber = 1;
                $(".add-more").show();
                $("#hislistnew_id").html(getHtml(ret));
            }
        })
    }
    function getHtml(ret) {
        var data = ret.Data;
        var datapno = data.pageNo;
        var datapageCount = data.pageCount;
        if (datapno < datapageCount) {
            $(".add-more").html("<a  href='javascript:paging(); '>点击加载更多</a>");
        }
        if (datapageCount < datapno) {
            $(".add-more").html("已加载完全部商品");
            return false;
        }
        var dataitem = ret.Data.list;

        var h = "";
        for (var i = 0; i < dataitem.length; i++) {
            var amounttotal = dataitem[i].amount - dataitem[i].djamount;  //可用库存

            h += "<li class='row-item' pid='" + dataitem[i].id + "' >";
            h += "<div class='list-title fl " + (i % 2 !== 1 ? 'even' : 'odd') + "'>";
            h += "<h1>" + (pnumber++) + "</h1>";
            h += "<p>已购" + dataitem[i].buyamount + "件</p>";
            h += "</div>";
            h += "<div class='pic'>";
            h += "<a href='/product/info?priceid=" + dataitem[i].id + "' target='_blank'>";
            h += "<img src='" + getRandomFileserver() + dataitem[i].photo + "' width='120' height='120' onerror='this.src=\"" + ctx + "/website/images/noimg.jpg\"'>";
            h += "</a></div>";
            h += "<div class='text title'>";
            h += "<h3><a href='/product/info?priceid=" + dataitem[i].id + "' target='_blank'>" + dataitem[i].productname + "</a></h3>";
            h += "<p>厂家：" + dataitem[i].b_chanjia + "</p>";
            h += "<p>规格：" + dataitem[i].b_guige + "</p>";
            h += "</div>";
            h += " <div class='text details'>";
            if (!dataitem[i].b_tymz) {
                h += " <p> <em style='letter-spacing: 6px'>通用</em>名：无</p>";
            }else {
                h += " <p> <em style='letter-spacing: 6px'>通用</em>名："+ dataitem[i].b_tymz +"</p>";
            }
            h += "<p>批准文号：" + dataitem[i].b_pzwh + "</p>";
            h += "</div>";
            h += "<div class='text cost'>"
            if (dataitem[i].canbuy == 1) {
                if (dataitem[i].promotion_flash_sale) {
                    h += "<p><strong>￥" + dataitem[i].pg_price + "</strong></p>";
                }else {
                    h += "<p><strong>￥" + dataitem[i].price + "</strong></p>";
                }
            } else {
                h += "<p style='color: #FF6767;'>不在本区域销售</p>";
            }
            h += "<p>";
            if (dataitem[i].status > 1) {
                if (dataitem[i].moneyoffType != "") {
                    if (dataitem[i].promotion_coupon) {
                        h += "<span>券</span>";
                    }
                    if (dataitem[i].promotion_flash_sale) {
                        h += "<span>特价</span>";
                    }
                    if (dataitem[i].promotion_buy_send) {
                        h += "<span>买送</span>";
                    }
                    if (dataitem[i].promotion_money_off) {
                        h += "<span>满减</span>";
                    }
                    if (dataitem[i].promotion_purchase_gift) {
                        h += "<span>满赠</span>";
                    }
                }
            }
            h += "</p>";
            h += "</div>";
            h += "<div class='row-btn'>";
            //已下架商品
            if (dataitem[i].status <= 1) {
                h += "<div class='fl'>";
                h += "</div>";
                h += "<div class='buy-btn2 buy-add-cart fl'>";
                h += "</div>";
                h += "<div class='clearfix' style='color: #888; font-size:12px;'>商品已下架</div>";
                h += "<p class='repertory'></p>";
            }
            if (dataitem[i].status > 1) {
                h += "<div class='fl'>";
                h += " <div class='buy-Num-bd fl'>";
                if (dataitem[i].promotion_flash_sale) {
                    if (!dataitem[i].fs_amount){
                        h += "<input type='text' name='amount' onkeyup='inputAmount(this)' class='buy-numInp' maxnum=0 style='height:16px;line-height:16px;' value='1'>";
                    }else {
                        h += "<input type='text' name='amount' onkeyup='inputAmount(this)' class='buy-numInp' maxnum='" +dataitem[i].fs_amount + "' style='height:16px;line-height:16px;' value='1'>";
                    }
                    h += " <span class='btn-reduce' onclick='lessenamount(this)'>-</span>";
                    h += "<span class='btn-add' onclick='addamount(this)'>+</span>";
                }else {
                    h += "<input type='text' name='amount' onkeyup='inputAmount(this)' class='buy-numInp' maxnum='" + amounttotal + "' style='height:16px;line-height:16px;' value='1'>";
                    h += " <span class='btn-reduce' onclick='lessenamount(this)'>-</span>";
                    h += "<span class='btn-add' onclick='addamount(this)'>+</span>";
                }


                h += "</div>";
                h += "</div>";
                h += "<div class='buy-btn2 buy-add-cart fl'>";
                if (dataitem[i].promotion_flash_sale) {
                    if (!dataitem[i].fs_amount || !dataitem[i].canbuy ) {
                        h += "<a href='javascript:void(0);'  class=''><i></i>加入购物车</a>";
                    } else {
                        h += "<a href='javascript:;' onclick='addtocart(" + dataitem[i].id + ",this)' class='can'><i></i>加入购物车</a>";
                    }
                }else {
                    if (amounttotal < 1 || !dataitem[i].canbuy ) {
                    h += "<a href='javascript:void(0);'  class=''><i></i>加入购物车</a>";
                } else {
                    h += "<a href='javascript:;' onclick='addtocart(" + dataitem[i].id + ",this)' class='can'><i></i>加入购物车</a>";
                }}

                h += "</div>";
                h += "<div class='clearfix'></div>";
                if (dataitem[i].promotion_flash_sale) {
                        if (dataitem[i].fs_amount >0) {
                            h += "<p class='repertory'>库存：" + dataitem[i].fs_amount + "</p>";
                        } else {
                            h += "<p class='repertory'>库存：无</p>";
                        }
                } else {
                        if (amounttotal < 1) {
                            h += "<p class='repertory'>库存：无</p>";
                        } else {
                            h += "<p class='repertory'>库存：" + amounttotal + "</p>";
                        }
                    }


            }
            h += "</div>";
            h += "</li>";

        }
        return h;
    }

    function paging() {
        pno++;
        var timeType = selectgr();
        $w.httpRequest({
            url: ctx + "/order/hislistnew",
            data: {"pno": pno, "timeType": timeType, "platform" : 1},
            ok: function (ret) {
                $("#hislistnew_id").append(getHtml(ret));
            }
        });
    }

</script>


<script>
    var uploader;
    $(function () {
        setLeftCur("lscg");

        $('.J_select').each(function () {
            if ($(this).prev().get(0).checked)
                $(this).parent().addClass('checked');
        })

        $('.J_select').click(function () {
            var ischeck = false;
            if ($(this).parent().get(0).className.indexOf("checked") == -1) ischeck = true;
            checkbox($(this).parent(), ischeck);
            if ($(this).parent().get(0).className.indexOf("allbox") != -1) selall(ischeck);
            if (!ischeck) {
                $(".allbox").each(function () {
                    checkbox($(this), ischeck);
                })
            }
        })
    })

    function addamount(obj) {
        var txt = $("[name='amount']", $(obj).parent());
        var n = parseInt(txt.val());
        n++;
        txt.val(n);
        inputAmount(txt);
    }
    function lessenamount(obj) {
        var txt = $("[name='amount']", $(obj).parent());
        var n = parseInt(txt.val());
        n--;
        txt.val(n);
        inputAmount(txt);
    }
    function addtocart(pid) {
        var url = ctx + "/order/addToCart?pid=" + pid + "&amount=" + $("[name='amount']", $("[pid='" + pid + "']")).val();
//        window.open(url);
        $w.addtocart(url);
    }
    function selall(ischeck) {
        $(".productbox").each(function () {
            checkbox($(this), ischeck);
        })
    }
    function checkbox(obj, ischeck) {
        if (ischeck) {
            if (obj.get(0).className.indexOf("checked") == -1) {
                obj.addClass("checked");
            }
        } else obj.removeClass("checked");
        $("[name='cartcheckbox']", obj).get(0).checked = ischeck;

    }
    function query() {
        gopage(1);
    }
    function gopage(n) {
        var url = ctx + "/order/hislist?pno=" + n;
        window.location.href = url;
    }
    function topageclick() {
        if ($("[name='topagenum']").val() != "")
            gopage($("[name='topagenum']").val());
    }
    $(".go-top").click(function () {
        var top_dis = $(document).scrollTop();
        if (top_dis > 0) {
            $("html, body").animate({scrollTop: 0}, 500);
        }
    });
</script>